package code.phpnet
{
	import flash.net.Responder;
	public class TableRo extends PhpServer
	{
		private var tableexpiretime:int=10;//过期时间
		private var _cb:Function;//回调
		public function TableRo()
		{
			super();
		}
		
		/**
		 * ttype  请求桌子类型(1普通房间，2比赛房间....)
		 * fresh  强制刷新（0不强制刷新，1强制刷新）
		 */
		public function getAllTables(cb:Function,ttype:int, fresh:int=0):void 
		{
			_cb = cb;
			if ( (fresh == 0)&& (typeof(_globalParam.CC.TT[ttype]) != 'undefined') && ((new Date()).valueOf()-_globalParam.CC.TT[ttype] < tableexpiretime* 1000)) { //符合缓存条件
				trace( _globalParam.CC.T[ttype]);
			}else {//获取游戏桌.
				var param:Array = new Array();
				param[0] = ttype;
				this.oConnect.call("table.getall", new Responder(onGetGameZoneTables, serverFault), this.genParam( param));
			}	
		}
		
		/**
		 *获取桌子列表 
		 * @param rets
		 * 
		 */
		private function onGetGameZoneTables(rets:Object):void 
		{
			var ret:Object = this.getRet(rets);
			if ( rets['flag'] == 1&& rets['check']&&rets['error']) { //从服务端返回的数据,缓存起来
				_globalParam.CC.T[ret['ttype']] = ret['ret'];
				_globalParam.CC.TT[ret['ttype']] = (new Date()).valueOf();
				if(Boolean(_cb)) {
					_cb(ret)
				}
			}
		}
	}
}